package com.neusoft.yuejian_6.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.neusoft.yuejian_6.R;
import com.neusoft.yuejian_6.activity.PrizeInfoActivity;
import com.neusoft.yuejian_6.javabean.Prize;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Q on 2017/11/1.
 */

public class PrizeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContex;
    private List mDataList;
    private ViewHolder viewHolder;
    private LayoutInflater mLayoutInflater;

    public PrizeAdapter(Context mContext, List mDataList) {
        this.mContex = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).
                inflate(R.layout.cardview_prize, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Prize entity = (Prize) mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.prize_intro.setText(entity.getPrize_intro());
        viewHolder.prize_name.setText(entity.getPrize_name());
        viewHolder.prize_amount.setText(entity.getPrize_amount());
        //Log.d("s","post_time");
        String prize_pic = "http://10.0.2.2/neu1_yuejian/Public/Admin/photo/" + entity.getPrize_pic();
        //System.out.print("pic");
        if (!prize_pic.equals("")) {
            Picasso.with(mContex).load(prize_pic).error(R.drawable.ic_add).into(viewHolder.prize_pic);
        }

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle=new Bundle();
                bundle.putInt("prize_id",entity.getPrize_id());
                bundle.putString("prize_name",entity.getPrize_name());
                bundle.putString("prize_amount",entity.getPrize_amount());
                bundle.putString("prize_intro",entity.getPrize_intro());
                bundle.putString("prize_pic",entity.getPrize_pic());
//                bundle.putString("t_time",entity.getT_time());
//                bundle.putString("t_picture",entity.getT_picture());
//                bundle.putString("t_phone",entity.getT_phone());
                Intent intent=new Intent(mContex, PrizeInfoActivity.class);
                intent.putExtras(bundle);
                mContex.startActivity(intent);
            }});
    }


    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView prize_pic;
        TextView prize_name, prize_intro,prize_amount;

        public ViewHolder(View itemView) {
            super(itemView);
            prize_name = (TextView) itemView.findViewById(R.id.prize_name);
            prize_intro = (TextView) itemView.findViewById(R.id.prize_intro);
            prize_amount = (TextView) itemView.findViewById(R.id.prize_amount);
            prize_pic = (ImageView) itemView.findViewById(R.id.prize_pic);
        }
    }
}